<?php

global $_GPC;
global $_W;
$userid = $_GPC['userid'];
if (!$userid) {
    message('请先登录', $this->createMobileUrl('login'), 'error');
}
$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
$user = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_user') . ' WHERE id =:a', array(':a' => $userid));
if (!$user || !$user['status']) {
    message('账号异常', '', 'error');
}
$shop = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_group') . ' WHERE id =:a', array(':a' => $user['pcate']));
$shopid = $shop['id'];
$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
$ptype = $_GPC['ptype'];
$orderid = $_GPC['orderid'];
$iskey = $_GPC['iskey'];
$event = $_GPC['event'] ? $_GPC['event'] : 'print';
$printer = $_GPC['printer'];
if ($operation == 'display') {
    include $this->template($cfg['floder'] . '/print');
} else {
    if ($operation == 'message') {
        $list = pdo_fetchall('SELECT * FROM ' . tablename('j_hmoney_msg') . ' WHERE groupid=:a and (touser=0 || touser=:b) and status=0 order by id desc', array(':a' => $shopid, ':b' => $userid));
        if (!count($list)) {
            exit(json_encode(array('success' => false)));
        }
        exit(json_encode(array('success' => true, 'list' => $list)));
    } else {
        if ($operation == 'updatemessage') {
            $mid = intval($_GPC['mid']);
            $message = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_msg') . ' WHERE id =:a', array(':a' => $mid));
            if (!$message || $message['status']) {
                exit(json_encode(array('success' => false)));
            }
            pdo_update('j_hmoney_msg', array('status' => 1, 'endtime' => TIMESTAMP), array('id' => $mid));
            exit(json_encode(array('success' => true)));
        } else {
            if ($operation != 'getcookerlist') {
                if ($operation == 'print') {
                    $print = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_print') . ' WHERE weid = \'' . $_W['uniacid'] . '\' and pcate=\'' . $ptype . '\' and groupid=:a order by isdefault desc,id desc limit 1', array(':a' => $shopid));
                    $printdoc = $print['wpcontent'];
                    switch ($ptype) {
                        case 1:
                            $trade = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_order') . ' WHERE weid = \'' . $_W['uniacid'] . '\' and id=:a ', array(':a' => $orderid));
                            $username = pdo_fetchcolumn('SELECT realname FROM ' . tablename('j_hmoney_user') . ' WHERE id=:a ', array(':a' => $trade['userid']));
                            $table = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_table') . ' WHERE weid = \'' . $_W['uniacid'] . '\' and id=:a ', array(':a' => $trade['tableid']));
                            $tablepcate = pdo_fetchcolumn('SELECT title FROM ' . tablename('j_hmoney_tablecategory') . ' WHERE id=:a ', array(':a' => $table['pcate']));
                            $goodlist = pdo_fetchall('SELECT a.*,b.unitname FROM ' . tablename('j_hmoney_ordergoods') . ' as a LEFT JOIN ' . tablename('j_hmoney_goods') . ' as b ON a.goodid=b.id  WHERE a.orderid=:a order by a.id desc ', array(':a' => $orderid));
                            $printdoc = str_replace('{收银员}', $username, $printdoc);
                            $printdoc = str_replace('{订单号}', $trade['out_trade_no'], $printdoc);
                            $printdoc = str_replace('{流水号}', $trade['serialnum'], $printdoc);
                            $printdoc = str_replace('{总金额}', $this->_2money($trade['order_fee']), $printdoc);
                            $printdoc = str_replace('{应付}', $this->_2money($trade['total_fee']), $printdoc);
                            $printdoc = str_replace('{不打折金额}', $this->_2money($trade['notdiscount_fee'] + $trade['teafee']), $printdoc);
                            $printdoc = str_replace('{打折金额}', $this->_2money($trade['order_fee'] - $trade['notdiscount_fee']), $printdoc);
                            $printdoc = str_replace('{优惠}', $this->_2money($trade['discount_fee']), $printdoc);
                            $printdoc = str_replace('{实付}', $this->_2money($trade['paid_fee']), $printdoc);
                            $printdoc = str_replace('{客付}', $this->_2money($trade['paid_fee'] + $trade['change_fee']), $printdoc);
                            $printdoc = str_replace('{找零}', $this->_2money($trade['change_fee']), $printdoc);
                            $printdoc = str_replace('{茶位费}', $this->_2money($trade['teafee']), $printdoc);
                            $printdoc = str_replace('{人数}', $trade['person'], $printdoc);
                            $printdoc = str_replace('{备注}', $trade['remark'], $printdoc);
                            $printdoc = str_replace('{房台}', $tablepcate . '-' . $table['title'], $printdoc);
                            if ($trade['memberno']) {
                                $member = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_membercard') . ' WHERE weid = \'' . $_W['uniacid'] . '\' and id=:a', array(':a' => $trade['memberno']));
                                $printdoc = str_replace('{会员卡号}', $member['cardno'] ? $member['cardno'] : $member['wxcardno'], $printdoc);
                                $cash = $this->_2money($member['cash']);
                                if ($member['uid']) {
                                    load()->model('mc');
                                    $creditAry = mc_credit_fetch($member['uid'], array(0 => 'credit2'));
                                    $cash = $creditAry['credit2'];
                                }
                                $printdoc = str_replace('{余额}', $cash, $printdoc);
                            } else {
                                $printdoc = str_replace('{会员卡号}', '-', $printdoc);
                                $printdoc = str_replace('{余额}', '-', $printdoc);
                            }
                            $ispay = '未支付';
                            if ($trade['ispay'] == 0) {
                                $ispay = '未支付';
                            } else {
                                if ($trade['ispay'] == 1) {
                                    $ispay = '已付款';
                                }
                            }
                            $printdoc = str_replace('{支付}', $ispay, $printdoc);
                            $printdoc = str_replace('{状态}', _orderGoodsStatus($trade['status']), $printdoc);
                            if ($trade['paytype2'] > -1) {
                                $str = _getPaytpye($trade['paytype'], $shopid) . '￥' . $this->_2money($trade['paid_fee1']) . "\\n" . _getPaytpye($trade['paytype2'], $shopid) . '￥' . $this->_2money($trade['paid_fee2']);
                                $printdoc = str_replace('{付款方式}', $str, $printdoc);
                            } else {
                                $printdoc = str_replace('{付款方式}', _getPaytpye($trade['paytype'], $shopid), $printdoc);
                            }
                            $printdoc = str_replace('{开台时间}', date('m/d H:i', $trade['createtime']), $printdoc);
                            $printdoc = str_replace('{日期}', $trade['createdate'], $printdoc);
                            $printdoc = str_replace('{时间}', date('H:i', $trade['createtime']), $printdoc);
                            $printdoc = str_replace('{二维码}', '<QR>' . $trade['qrcode'] . '</QR>', $printdoc);
                            $goodstr = '';
                            foreach ($goodlist as $row) {
                                $goodstr .= formatPrintStr($row['title'], 14) . '  ' . formatPrintStr($row['num'] . $row['unitname'], 6) . formatPrintStr($this->_2money($row['total_fee']), 6) . "\\n";
                                if ($row['taste'] || $row['ispack']) {
                                    if ($row['taste']) {
                                        $goodstr .= $row['taste'];
                                    }
                                    if ($row['ispack'] == 1) {
                                        $goodstr .= ' (打包)';
                                    }
                                    $goodstr .= "\\n";
                                }
                            }
                            $printdoc = str_replace('{商品}', $goodstr, $printdoc);
                            exit(json_encode(array('success' => true, 'content' => $printdoc, 'printtype' => $ptype, 'num' => intval($print['num']) ? $print['num'] : 1)));
                            break;
                        case 2:
                            $trade = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_order') . ' WHERE weid = \'' . $_W['uniacid'] . '\' and id=:a ', array(':a' => $orderid));
                            $username = pdo_fetchcolumn('SELECT realname FROM ' . tablename('j_hmoney_user') . ' WHERE id=:a ', array(':a' => $trade['userid']));
                            $table = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_table') . ' WHERE weid = \'' . $_W['uniacid'] . '\' and id=:a ', array(':a' => $trade['tableid']));
                            $tablepcate = pdo_fetchcolumn('SELECT title FROM ' . tablename('j_hmoney_tablecategory') . ' WHERE id=:a ', array(':a' => $table['pcate']));
                            if (!$iskey || $iskey == 'all') {
                                $goodlist = pdo_fetchall('SELECT a.*,b.memberprice,b.unitname,b.marketprice,b.cooker FROM ' . tablename('j_hmoney_ordergoods') . ' as a LEFT JOIN ' . tablename('j_hmoney_goods') . ' as b ON a.goodid=b.id  WHERE a.orderid=:a order by a.id desc ', array(':a' => $orderid));
                            } else {
                                if ($iskey == 'new') {
                                    $goodlist = pdo_fetchall('SELECT a.*,b.memberprice,b.unitname,b.marketprice,b.cooker FROM ' . tablename('j_hmoney_ordergoods') . ' as a LEFT JOIN ' . tablename('j_hmoney_goods') . ' as b ON a.goodid=b.id  WHERE a.orderid=:a and a.isprint=0 order by a.id desc ', array(':a' => $orderid));
                                } else {
                                    $goodlist = pdo_fetchall('SELECT a.*,b.memberprice,b.unitname,b.marketprice,b.cooker FROM ' . tablename('j_hmoney_ordergoods') . ' as a LEFT JOIN ' . tablename('j_hmoney_goods') . ' as b ON a.goodid=b.id  WHERE a.id in(' . $iskey . ') order by a.id desc ');
                                }
                            }
                            $printdoc = str_replace('{收银员}', $username, $printdoc);
                            $printdoc = str_replace('{订单号}', $trade['out_trade_no'], $printdoc);
                            $printdoc = str_replace('{流水号}', $trade['serialnum'], $printdoc);
                            $printdoc = str_replace('{总金额}', $this->_2money($trade['order_fee']), $printdoc);
                            $printdoc = str_replace('{应付}', $this->_2money($trade['total_fee']), $printdoc);
                            $printdoc = str_replace('{优惠}', $this->_2money($trade['discount_fee']), $printdoc);
                            $printdoc = str_replace('{实付}', $this->_2money($trade['paid_fee']), $printdoc);
                            $printdoc = str_replace('{茶位费}', $this->_2money($trade['teafee']), $printdoc);
                            $printdoc = str_replace('{人数}', $trade['person'], $printdoc);
                            $printdoc = str_replace('{房台}', $tablepcate . '-' . $table['title'], $printdoc);
                            if ($trade['memberno']) {
                                $member = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_membercard') . ' WHERE weid = \'' . $_W['uniacid'] . '\' and id=:a', array(':a' => $trade['memberno']));
                                $printdoc = str_replace('{会员卡号}', $member['cardno'] ? $member['cardno'] : $member['wxcardno'], $printdoc);
                                $printdoc = str_replace('{余额}', $this->_2money($member['cash']), $printdoc);
                            } else {
                                $printdoc = str_replace('{会员卡号}', '-', $printdoc);
                                $printdoc = str_replace('{余额}', '-', $printdoc);
                            }
                            $ispay = '未支付';
                            if ($trade['ispay'] == 0) {
                                $ispay = '未支付';
                            } else {
                                if ($trade['ispay'] == 1) {
                                    $ispay = '已付款';
                                }
                            }
                            $printdoc = str_replace('{支付}', $ispay, $printdoc);
                            $printdoc = str_replace('{状态}', _orderGoodsStatus($trade['status']), $printdoc);
                            if ($trade['paytype2'] > -1) {
                                $str = _getPaytpye($trade['paytype']) . '￥' . $this->_2money($trade['paid_fee1']) . "\\n" . _getPaytpye($trade['paytype2']) . '￥' . $this->_2money($trade['paid_fee2']);
                                $printdoc = str_replace('{付款方式}', $str, $printdoc);
                            } else {
                                $printdoc = str_replace('{付款方式}', _getPaytpye($trade['paytype']), $printdoc);
                            }
                            $printdoc = str_replace('{开台时间}', date('m/d H:i', $trade['createtime']), $printdoc);
                            $printdoc = str_replace('{日期}', $trade['createdate'], $printdoc);
                            $printdoc = str_replace('{时间}', date('H:i'), $printdoc);
                            $printdoc = str_replace('{二维码}', $trade['qrcode'] ? '<QR>' . $trade['qrcode'] . '</QR>' : '', $printdoc);
                            $goodstr = '';
                            foreach ($goodlist as $row) {
                                $goodstr .= formatPrintStr($row['title'], 14) . '  ' . $row['num'] . $row['unitname'] . "\\n";
                                if ($row['taste'] || $row['ispack']) {
                                    if ($row['taste']) {
                                        $goodstr .= $row['taste'];
                                    }
                                    if ($row['ispack'] == 1) {
                                        $goodstr .= ' (打包)';
                                    }
                                    $goodstr .= "\\n";
                                }
                            }
                            $printdoc = str_replace('{商品}', $goodstr, $printdoc);
                            exit(json_encode(array('success' => true, 'content' => $printdoc, 'printtype' => $ptype, 'num' => intval($print['num']) ? $print['num'] : 1)));
                            break;
                        case 3:
                            $trade = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_order') . ' WHERE weid = \'' . $_W['uniacid'] . '\' and id=:a ', array(':a' => $orderid));
                            $table = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_table') . ' WHERE weid = \'' . $_W['uniacid'] . '\' and id=:a ', array(':a' => $trade['tableid']));
                            $tablepcate = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_tablecategory') . ' WHERE id=:a ', array(':a' => $table['pcate']));
                            if (!$iskey || $iskey == 'all') {
                                $goodlist = pdo_fetchall('SELECT a.*,b.memberprice,b.unitname,b.marketprice,b.cooker FROM ' . tablename('j_hmoney_ordergoods') . ' as a LEFT JOIN ' . tablename('j_hmoney_goods') . ' as b ON a.goodid=b.id  WHERE a.orderid=:a order by a.id desc ', array(':a' => $orderid));
                            } else {
                                if ($iskey == 'new') {
                                    $goodlist = pdo_fetchall('SELECT a.*,b.memberprice,b.unitname,b.marketprice,b.cooker FROM ' . tablename('j_hmoney_ordergoods') . ' as a LEFT JOIN ' . tablename('j_hmoney_goods') . ' as b ON a.goodid=b.id  WHERE a.orderid=:a and a.isprint=0 order by a.id desc ', array(':a' => $orderid));
                                } else {
                                    $goodlist = pdo_fetchall('SELECT a.*,b.memberprice,b.unitname,b.marketprice,b.cooker FROM ' . tablename('j_hmoney_ordergoods') . ' as a LEFT JOIN ' . tablename('j_hmoney_goods') . ' as b ON a.goodid=b.id  WHERE a.id in(' . $iskey . ') order by a.id desc ');
                                }
                            }
                            foreach ($goodlist as $row) {
                                pdo_update('j_hmoney_ordergoods', array('isprint' => $row['isprint'] + 1, 'kprinttime' => TIMESTAMP), array('id' => $row['id']));
                            }
                            pdo_update('j_hmoney_table', array('newctrl' => 0), array('id' => $trade['tableid']));
                            $username = pdo_fetchcolumn('SELECT useracount FROM ' . tablename('j_hmoney_user') . ' WHERE id =:a', array(':a' => $trade['userid']));
                            $printdoc = str_replace('{收银员}', $username, $printdoc);
                            $printdoc = str_replace('{订单号}', $trade['out_trade_no'], $printdoc);
                            $printdoc = str_replace('{流水号}', $trade['serialnum'], $printdoc);
                            $printdoc = str_replace('{总金额}', $this->_2money($trade['order_fee']), $printdoc);
                            $printdoc = str_replace('{应付}', $this->_2money($trade['total_fee']), $printdoc);
                            $printdoc = str_replace('{优惠}', $this->_2money($trade['discount_fee']), $printdoc);
                            $printdoc = str_replace('{实付}', $this->_2money($trade['paid_fee']), $printdoc);
                            $printdoc = str_replace('{茶位费}', $this->_2money($trade['teafee']), $printdoc);
                            $printdoc = str_replace('{人数}', $trade['person'], $printdoc);
                            $printdoc = str_replace('{房台}', $tablepcate['title'] . '-' . $table['title'], $printdoc);
                            $ispay = '未支付';
                            if ($trade['ispay'] == 0) {
                                $ispay = '未支付';
                            } else {
                                if ($trade['ispay'] == 1) {
                                    $ispay = '已付款';
                                }
                            }
                            $printdoc = str_replace('{支付}', $ispay, $printdoc);
                            $printdoc = str_replace('{状态}', _orderGoodsStatus($trade['status']), $printdoc);
                            $printdoc = str_replace('{付款方式}', _getPaytpye($trade['paytype']), $printdoc);
                            $printdoc = str_replace('{开台时间}', date('m/d H:i', $trade['createtime']), $printdoc);
                            $printdoc = str_replace('{日期}', date('m/d'), $printdoc);
                            $printdoc = str_replace('{时间}', date('H:i'), $printdoc);
                            $pasuOrderStr = '';
                            if ($table['pauseorder'] == 1) {
                                $pasuOrderStr = '(等菜)';
                                $printdoc .= "\\n****等菜****";
                            }
                            if ($table['pauseorder'] == 2) {
                                $pasuOrderStr = '(上菜)';
                                $printdoc .= "\\n****上菜****";
                            }
                            $cooklist = pdo_fetchall('SELECT * FROM ' . tablename('j_hmoney_cookprint') . ' WHERE groupid=:a order by id desc ', array(':a' => $trade['groupid']));
                            $cookary = array();
                            $cookary2 = array();
                            $cookName = array();
                            foreach ($cooklist as $row) {
                                $cookary[$row['id']] = $row['ptype'];
                                $temp = json_decode($row['param'], true);
                                $cookary2[$row['id']] = $temp;
                                $cookName[$row['id']] = $row['title'];
                            }
                            $goodWpAry = array();
                            $goodsAry = array();
                            $goodsingleAry = array();
                            $printAry = array();
                            $goodstr = '';
                            foreach ($goodlist as $row) {
                                $goodstr .= $row['title'] . $pasuOrderStr . "\\n";
                                if ($row['taste'] || $row['ispack']) {
                                    if ($row['taste']) {
                                        $goodstr .= $row['taste'];
                                    }
                                    if ($row['ispack'] == 1) {
                                        $goodstr .= ' (打包)';
                                    }
                                    $goodstr .= "\\n";
                                }
                                $goodstr .= '<R>' . $row['num'] . $row['unitname'] . "</R>\\n";
                            }
                            if ($cooklist) {
                                foreach ($goodlist as $row) {
                                    if ($cookary[$row['cooker']] == 0) {
                                        if (!isset($goodsingleAry[$row['cooker']])) {
                                            $goodsingleAry[$row['cooker']] = array();
                                        }
                                        $goodstr = $row['title'] . $pasuOrderStr . "\\n";
                                        if ($row['taste'] || $row['ispack']) {
                                            if ($row['taste']) {
                                                $goodstr .= $row['taste'];
                                            }
                                            if ($row['ispack'] == 1) {
                                                $goodstr .= ' (打包)';
                                            }
                                            $goodstr .= "\\n";
                                        }
                                        $goodstr .= '                  ' . $row['num'] . $row['unitname'] . "\\n";
                                        $goodsingleAry[$row['cooker']][] = $goodstr;
                                    } else {
                                        if ($shop['printseparate']) {
                                            $result = _print_api($row['cooker'], $printdoc, array(0 => $row));
                                            if ($cfg['debug']) {
                                                var_dump($result);
                                            }
                                        } else {
                                            if (!isset($goodWpAry[$row['cooker']])) {
                                                $goodWpAry[$row['cooker']] = array();
                                            }
                                            $goodWpAry[$row['cooker']][] = $row;
                                        }
                                    }
                                }
                                if (!$shop['printseparate']) {
                                    foreach ($goodWpAry as $index => $row) {
                                        $result = _print_api($index, $printdoc, $row);
                                        if ($cfg['debug']) {
                                            var_dump($printresult);
                                        }
                                    }
                                }
                                foreach ($goodsAry as $index => $row) {
                                    $temp = $printdoc;
                                    $temp = str_replace('{厨房}', $cookName[$index], $temp);
                                    $printAry[$index]['printdoc'] = $temp;
                                    $temp = str_replace('{商品}', $row, $temp);
                                    $printAry[$index]['param'] = $cookary2[$index];
                                    $printAry[$index]['str'] = $temp;
                                    $printAry[$index]['goods'] = $goodsingleAry[$index];
                                    $printAry[$index]['printseparate'] = intval($shop['printseparate']);
                                }
                            }
                            exit(json_encode(array('success' => true, 'content' => $printAry, 'pcateip' => $tablepcate['printerip'], 'printtype' => $ptype, 'num' => intval($print['num']) ? $print['num'] : 1)));
                            break;
                        case 31:
                            $print = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_print') . ' WHERE weid = \'' . $_W['uniacid'] . '\' and pcate=\'3\' and groupid=:a order by isdefault desc,id desc limit 1', array(':a' => $shopid));
                            $printdoc = $print['wpcontent'];
                            $refundorder = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_refund') . ' WHERE weid = \'' . $_W['uniacid'] . '\' and id=:a ', array(':a' => $orderid));
                            $trade = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_order') . ' WHERE weid = \'' . $_W['uniacid'] . '\' and id=:a ', array(':a' => $refundorder['orderid']));
                            $table = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_table') . ' WHERE weid = \'' . $_W['uniacid'] . '\' and id=:a ', array(':a' => $trade['tableid']));
                            $tablepcate = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_tablecategory') . ' WHERE id=:a ', array(':a' => $table['pcate']));
                            $goods = pdo_fetch('SELECT * FROM  ' . tablename('j_hmoney_goods') . '  WHERE id=:a  ', array(':a' => $refundorder['gid']));
                            if (!$goods['cooker']) {
                                exit(json_encode(array('success' => true, 'content' => '', 'printtype' => 31, 'num' => 1)));
                            }
                            $username = pdo_fetchcolumn('SELECT useracount FROM ' . tablename('j_hmoney_user') . ' WHERE id =:a', array(':a' => $trade['userid']));
                            $printdoc = str_replace('{收银员}', $username, $printdoc);
                            $printdoc = str_replace('{订单号}', $trade['out_trade_no'], $printdoc);
                            $printdoc = str_replace('{流水号}', $trade['serialnum'], $printdoc);
                            $printdoc = str_replace('{总金额}', $this->_2money($trade['order_fee']), $printdoc);
                            $printdoc = str_replace('{应付}', $this->_2money($trade['total_fee']), $printdoc);
                            $printdoc = str_replace('{优惠}', $this->_2money($trade['discount_fee']), $printdoc);
                            $printdoc = str_replace('{实付}', $this->_2money($trade['paid_fee']), $printdoc);
                            $printdoc = str_replace('{茶位费}', $this->_2money($trade['teafee']), $printdoc);
                            $printdoc = str_replace('{人数}', $trade['person'], $printdoc);
                            $printdoc = str_replace('{房台}', $tablepcate['title'] . '-' . $table['title'], $printdoc);
                            $ispay = '未支付';
                            if ($trade['ispay'] == 0) {
                                $ispay = '未支付';
                            } else {
                                if ($trade['ispay'] == 1) {
                                    $ispay = '已付款';
                                }
                            }
                            $printdoc = str_replace('{支付}', $ispay, $printdoc);
                            $printdoc = str_replace('{状态}', _orderGoodsStatus($trade['status']), $printdoc);
                            $printdoc = str_replace('{付款方式}', _getPaytpye($trade['paytype']), $printdoc);
                            $printdoc = str_replace('{开台时间}', date('m/d H:i', $trade['createtime']), $printdoc);
                            $printdoc = str_replace('{日期}', date('m/d'), $printdoc);
                            $printdoc = str_replace('{时间}', date('H:i'), $printdoc);
                            $pasuOrderStr = '(退菜)';
                            $cooklist = pdo_fetchall('SELECT * FROM ' . tablename('j_hmoney_cookprint') . ' WHERE groupid=:a order by id desc ', array(':a' => $trade['groupid']));
                            $cookary = array();
                            $cookary2 = array();
                            $cookName = array();
                            foreach ($cooklist as $row) {
                                $cookary[$row['id']] = $row['ptype'];
                                $temp = json_decode($row['param'], true);
                                $cookary2[$row['id']] = $temp;
                                $cookName[$row['id']] = $row['title'];
                            }
                            $goodWpAry = array();
                            $goodsAry = array();
                            $goodsingleAry = array();
                            $printAry = array();
                            $goodstr = '';
                            if ($cooklist) {
                                if ($cookary[$row['cooker']] == 0) {
                                    if (!isset($goodsAry[$goods['cooker']])) {
                                        $goodsAry[$goods['cooker']] = '';
                                    }
                                    if (!isset($goodsingleAry[$goods['cooker']])) {
                                        $goodsingleAry[$goods['cooker']] = array();
                                    }
                                    $goodstr = $goods['title'] . $pasuOrderStr . "\\n";
                                    $goodstr .= '                  ' . $refundorder['num'] . $goods['unitname'] . "\\n";
                                    $goodsingleAry[$goods['cooker']][] = $goodstr;
                                } else {
                                    if ($shop['printseparate']) {
                                        $result = _print_api($goods['cooker'], $printdoc, array(0 => $row));
                                        if ($cfg['debug']) {
                                            var_dump($result);
                                        }
                                    } else {
                                        if (!isset($goodWpAry[$goods['cooker']])) {
                                            $goodWpAry[$goods['cooker']] = array();
                                        }
                                        $goodWpAry[$goods['cooker']][] = $row;
                                    }
                                }
                                if (!$shop['printseparate']) {
                                    foreach ($goodWpAry as $index => $row) {
                                        $result = _print_api($index, $printdoc, $row);
                                        if ($cfg['debug']) {
                                            var_dump($printresult);
                                        }
                                    }
                                }
                                foreach ($goodsAry as $index => $row) {
                                    $temp = $printdoc;
                                    $temp = str_replace('{厨房}', $cookName[$index], $temp);
                                    $printAry[$index]['printdoc'] = $temp;
                                    $temp = str_replace('{商品}', $row, $temp);
                                    $printAry[$index]['param'] = $cookary2[$index];
                                    $printAry[$index]['str'] = $temp;
                                    $printAry[$index]['goods'] = $goodsingleAry[$index];
                                    $printAry[$index]['printseparate'] = intval($shop['printseparate']);
                                }
                            }
                            exit(json_encode(array('success' => true, 'content' => $printAry, 'pcateip' => $tablepcate['printerip'], 'printtype' => 3, 'num' => intval($print['num']) ? $print['num'] : 1)));
                            break;
                        case 4:
                            $trade = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_recharge') . ' WHERE weid = \'' . $_W['uniacid'] . '\' and id=:a ', array(':a' => $orderid));
                            $member = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_membercard') . ' WHERE weid = \'' . $_W['uniacid'] . '\' and id=:a ', array(':a' => $trade['cid']));
                            $trade['username'] = $user['realname'];
                            $printdoc = str_replace('{收银员}', $user['realname'], $printdoc);
                            $printdoc = str_replace('{店铺}', $shop['companyname'], $printdoc);
                            $printdoc = str_replace('{订单号}', $trade['out_trade_no'], $printdoc);
                            $printdoc = str_replace('{金额}', $this->_2money($trade['cash']), $printdoc);
                            $printdoc = str_replace('{开始金额}', $this->_2money($trade['startfee']), $printdoc);
                            $printdoc = str_replace('{结束金额}', $this->_2money($trade['endfee']), $printdoc);
                            $printdoc = str_replace('{赠送金额}', $this->_2money($trade['gift']), $printdoc);
                            $printdoc = str_replace('{支付方式}', _getPaytpye($trade['paytype']), $printdoc);
                            $printdoc = str_replace('{备注}', $trade['remark'], $printdoc);
                            $printdoc = str_replace('{日期}', date('m月d日', $trade['createtime']), $printdoc);
                            $printdoc = str_replace('{时间}', date('H:i', $trade['createtime']), $printdoc);
                            $printdoc = str_replace('{卡号}', $member['cardno'], $printdoc);
                            $printdoc = str_replace('{微信卡号}', $member['wxcardno'], $printdoc);
                            $printdoc = str_replace('{打印时间}', date('m/d H:i'), $printdoc);
                            $doary = array(0 => '充值', 1 => '消费', 2 => '退还');
                            $printdoc = str_replace('{行为}', '充值', $printdoc);
                            exit(json_encode(array('success' => true, 'content' => $printdoc, 'printtype' => $ptype, 'num' => intval($print['num']) ? $print['num'] : 1)));
                            break;
                        case 5:
                            $refundorder = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_refund') . ' WHERE weid = \'' . $_W['uniacid'] . '\' and id=:a ', array(':a' => $orderid));
                            $trade = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_order') . ' WHERE weid = \'' . $_W['uniacid'] . '\' and id=:a ', array(':a' => $refundorder['orderid']));
                            $username = pdo_fetchcolumn('SELECT realname FROM ' . tablename('j_hmoney_user') . ' WHERE id=:a ', array(':a' => $refundorder['userid']));
                            $printdoc = str_replace('{处理人}', $username, $printdoc);
                            $printdoc = str_replace('{店铺}', $shop['companyname'], $printdoc);
                            $printdoc = str_replace('{订单号}', $trade['out_trade_no'], $printdoc);
                            $printdoc = str_replace('{退款单号}', $refundorder['out_refund_no'], $printdoc);
                            $printdoc = str_replace('{退款金额}', $this->_2money($refundorder['fee']), $printdoc);
                            $printdoc = str_replace('{原因}', $refundorder['remark'], $printdoc);
                            $printdoc = str_replace('{数量}', $refundorder['num'], $printdoc);
                            $printdoc = str_replace('{退款方式}', _getPaytpye($refundorder['paytype'], $shopid), $printdoc);
                            $printdoc = str_replace('{日期}', date('m月d日', $trade['createtime']), $printdoc);
                            $printdoc = str_replace('{时间}', date('H:i', $trade['createtime']), $printdoc);
                            $printdoc = str_replace('{打印时间}', date('m/d H:i'), $printdoc);
                            if ($refundorder['rtype'] == 2) {
                                $goods = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_ordergoods') . ' WHERE weid = \'' . $_W['uniacid'] . '\' and id=:a ', array(':a' => $refundorder['gid']));
                                $printdoc = str_replace('{商品}', $goods['title'], $printdoc);
                            }
                            $printdoc = str_replace('{商品}', '', $printdoc);
                            exit(json_encode(array('success' => true, 'content' => $printdoc, 'printtype' => $ptype, 'num' => intval($print['num']) ? $print['num'] : 1)));
                            break;
                        case 6:
                            $ordercount = pdo_fetch('SELECT count(*) as num1,sum(num) as num2,sum(paid_fee) as fee1,sum(teafee) as fee2,sum(total_fee) as fee3 FROM ' . tablename('j_hmoney_order') . ' WHERE  groupid =\'' . $shopid . '\' and userid=\'' . $userid . '\' and createtime>=\'' . $user['lasttime'] . '\' and createtime<=\'' . TIMESTAMP . '\' and ispay=1 ');
                            $orderpaycount = pdo_fetchall('SELECT paytype,sum(paid_fee) as fee1 FROM ' . tablename('j_hmoney_order') . ' WHERE  groupid =\'' . $shopid . '\' and userid=\'' . $userid . '\' and createtime>=\'' . $user['lasttime'] . '\' and createtime<=\'' . TIMESTAMP . '\' and ispay=1 group by paytype');
                            $chargecount = pdo_fetchall('SELECT paytype,sum(cash) as fee1 FROM ' . tablename('j_hmoney_recharge') . ' WHERE  groupid =\'' . $shopid . '\' and userid=\'' . $userid . '\' and createtime>=\'' . $user['lasttime'] . '\' and createtime<=\'' . TIMESTAMP . '\' and usetype=0 and  status=1 group by paytype');
                            $notcount = pdo_fetch('SELECT count(*) as num1 FROM ' . tablename('j_hmoney_order') . ' WHERE  groupid =\'' . $shopid . '\' and userid=\'' . $userid . '\' and createtime>=\'' . $user['lasttime'] . '\' and createtime<=\'' . TIMESTAMP . '\' and status<>2 ');
                            $item = array('ordernum' => intval($ordercount['num1']), 'goodsnum' => intval($ordercount['num2']), 'totalfee' => $this->_2money($ordercount['fee1'] + $ordercount['fee2']), 'allfee' => $this->_2money($ordercount['fee1']), 'teafee' => $this->_2money($ordercount['fee2']), 'goodsfee' => $this->_2money($ordercount['fee3']), 'notcount' => $notcount['num1']);
                            foreach ($orderpaycount as $row) {
                                $item['orderpay' . $row['paytype']] = $this->_2money($row['fee1']);
                            }
                            if (!$item['orderpay0']) {
                                $item['orderpay0'] = 0;
                            }
                            if (!$item['orderpay1']) {
                                $item['orderpay1'] = 0;
                            }
                            if (!$item['orderpay2']) {
                                $item['orderpay2'] = 0;
                            }
                            if (!$item['orderpay3']) {
                                $item['orderpay3'] = 0;
                            }
                            if (!$item['orderpay4']) {
                                $item['orderpay4'] = 0;
                            }
                            $temp = 0;
                            foreach ($chargecount as $row) {
                                $temp += $row['fee1'];
                                $item['chargepay' . $row['paytype']] = $this->_2money($row['fee1']);
                            }
                            if (!$item['chargepay0']) {
                                $item['chargepay0'] = 0;
                            }
                            if (!$item['chargepay1']) {
                                $item['chargepay1'] = 0;
                            }
                            if (!$item['chargepay2']) {
                                $item['chargepay2'] = 0;
                            }
                            if (!$item['chargepay3']) {
                                $item['chargepay3'] = 0;
                            }
                            $item['allcharge'] = $this->_2money($temp);
                            $item['username'] = $user['realname'];
                            $item['allcash'] = $item['orderpay2'] + $item['chargepay2'];
                            $printdoc = str_replace('{收银员}', $user['realname'], $printdoc);
                            $printdoc = str_replace('{店铺}', $shop['companyname'], $printdoc);
                            $printdoc = str_replace('{收银时间}', date('m/d H:i', $user['lasttime']) . '-' . date('m/d H:i'), $printdoc);
                            $printdoc = str_replace('{总销售额}', $item['totalfee'], $printdoc);
                            $printdoc = str_replace('{商品销售额}', $item['allfee'], $printdoc);
                            $printdoc = str_replace('{订单量}', $item['ordernum'], $printdoc);
                            $printdoc = str_replace('{商品量}', $item['goodsnum'], $printdoc);
                            $printdoc = str_replace('{茶位}', $item['teafee'], $printdoc);
                            $printdoc = str_replace('{销售收入}', $item['goodsfee'], $printdoc);
                            $printdoc = str_replace('{销售现金}', $item['orderpay2'], $printdoc);
                            $printdoc = str_replace('{销售银行卡}', $item['orderpay3'], $printdoc);
                            $printdoc = str_replace('{销售会员卡}', $item['orderpay4'], $printdoc);
                            $printdoc = str_replace('{销售微信}', $item['orderpay0'], $printdoc);
                            $printdoc = str_replace('{销售支付宝}', $item['orderpay1'], $printdoc);
                            $printdoc = str_replace('{充值收入}', $item['allcharge'], $printdoc);
                            $printdoc = str_replace('{充值现金}', $item['chargepay2'], $printdoc);
                            $printdoc = str_replace('{充值银行卡}', $item['chargepay1'], $printdoc);
                            $printdoc = str_replace('{充值微信}', $item['chargepay0'], $printdoc);
                            $printdoc = str_replace('{充值支付宝}', $item['chargepay1'], $printdoc);
                            $printdoc = str_replace('{应有现金}', $item['allcash'], $printdoc);
                            $printdoc = str_replace('{未完成订单}', $item['notcount'], $printdoc);
                            exit(json_encode(array('success' => true, 'content' => $printdoc, 'printtype' => $ptype, 'num' => intval($print['num']) ? $print['num'] : 1)));
                            break;
                        case 9:
                            if (!$printdoc) {
                                $printdoc = '店铺：{店铺}<BR>时间：{时间}<BR>总收益：{总收益}<BR>订单数：{订单数}<BR>销售商品：{销售商品}<BR>销售金额：{销售金额}<BR>优惠：{优惠}<BR>实付：{实付}<BR>茶位：{茶位}<BR>销售微信：{销售微信}<BR>销售支付宝：{销售支付宝}<BR>销售现金：{销售现金}<BR>销售银行卡：{销售银行卡}<BR>销售会员卡：{销售会员卡}<BR>充值总金额：{充值总金额}<BR>{销售自定义1}：{销售自定义1金额}<BR>{销售自定义2}：{销售自定义2金额}<BR>{销售自定义3}：{销售自定义3金额}<BR>{销售自定义4}：{销售自定义4金额}<BR>充值微信：{充值微信}<BR>充值支付宝：{充值支付宝}<BR>充值现金：{充值现金}<BR>充值银行卡：{充值银行卡}<BR>总退款：{总退款}<BR> 退款微信：{退款微信}<BR> 退款支付宝：{退款支付宝}<BR> 退款现金：{退款现金}<BR> 退款银行卡：{退款银行卡}<BR> 退款会员卡：{退款会员卡}<BR>总现金：{总现金}<BR> ';
                            }
                            $condition = ' and groupid =\'' . $shopid . '\' and createdate=\'' . date('Y-m-d') . '\' ';
                            $items = pdo_fetch('SELECT COUNT(*) as num1,sum(order_fee) as fee1,sum(discount_fee) as fee2,sum(total_fee) as fee3,sum(teafee) as fee4,sum(num) as num2 FROM ' . tablename('j_hmoney_order') . ' WHERE weid=\'' . $_W['uniacid'] . '\' ' . $condition . '  and ispay=1');
                            $paytypeList1 = pdo_fetchall('SELECT paytype,COUNT(*) as num1,sum(paid_fee1) as fee1 FROM ' . tablename('j_hmoney_order') . ' WHERE weid=\'' . $_W['uniacid'] . '\' ' . $condition . '  and ispay=1 group by paytype ');
                            $paytypeList2 = pdo_fetchall('SELECT paytype2,COUNT(*) as num1,sum(paid_fee2) as fee1 FROM ' . tablename('j_hmoney_order') . ' WHERE weid=\'' . $_W['uniacid'] . '\' ' . $condition . '  and ispay=1 and paytype2>-1 group by paytype2 ');
                            $paytypeList = array();
                            $temp = _getPaytpye('', $shopid);
                            foreach ($paytypeList1 as $row) {
                                $paytypeList[$row['paytype']] = array('num' => $row['num1'], 'fee1' => $row['fee1']);
                            }
                            foreach ($paytypeList2 as $row) {
                                $paytypeList[$row['paytype2']]['num'] = $paytypeList[$row['paytype2']]['num'] + $row['num1'];
                                $paytypeList[$row['paytype2']]['fee1'] = $paytypeList[$row['paytype2']]['fee1'] + $row['fee1'];
                            }
                            $holdorder = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('j_hmoney_order') . ' WHERE groupid =\'' . $shopid . '\'  and status=0 ');
                            $chargeitems = pdo_fetch('SELECT COUNT(*) as num1,sum(cash) as fee1 FROM ' . tablename('j_hmoney_recharge') . ' WHERE weid=\'' . $_W['uniacid'] . '\' ' . $condition . '  and status=1 and usetype=0 ');
                            $chargecount = pdo_fetchall('SELECT paytype,sum(cash) as fee1 FROM ' . tablename('j_hmoney_recharge') . ' WHERE weid=\'' . $_W['uniacid'] . '\' ' . $condition . ' and usetype=0 and  status=1 group by paytype');
                            $chargelist = array();
                            foreach ($chargecount as $row) {
                                $chargelist[$row['paytype']] = $row['fee1'];
                            }
                            $refunditems = pdo_fetchall('SELECT COUNT(*) as num1,sum(fee) as fee1,paytype FROM ' . tablename('j_hmoney_refund') . ' WHERE weid=\'' . $_W['uniacid'] . '\' ' . $condition . '  and status=1 group by paytype order by id desc ');
                            $refundlist = array();
                            $refundall = 0;
                            foreach ($refunditems as $row) {
                                $refundlist[$row['paytype']] = $row['fee1'];
                                $refundall += $row['fee1'];
                            }
                            $refundlist['all'] = $refundall;
                            $membercount = pdo_fetchcolumn('SELECT count(*) FROM ' . tablename('j_hmoney_membercard') . ' WHERE groupid =\'' . $shopid . '\' and createtime>=\'' . strtotime(date('Y-m-d 00:00:00')) . '\' ');
                            $printdoc = str_replace('{店铺}', $shop['companyname'], $printdoc);
                            $printdoc = str_replace('{时间}', date('Y-m-d H:i'), $printdoc);
                            $printdoc = str_replace('{总收益}', $this->_2money($items['fee3'] + $chargeitem['fee1']), $printdoc);
                            $printdoc = str_replace('{订单数}', intval($items['num1']), $printdoc);
                            $printdoc = str_replace('{销售商品}', intval($items['num2']), $printdoc);
                            $printdoc = str_replace('{销售金额}', $this->_2money($items['fee1']), $printdoc);
                            $printdoc = str_replace('{优惠}', $this->_2money($items['fee2']), $printdoc);
                            $printdoc = str_replace('{实付}', $this->_2money($items['fee3']), $printdoc);
                            $printdoc = str_replace('{茶位}', $this->_2money($items['fee4']), $printdoc);
                            $printdoc = str_replace('{销售微信}', $this->_2money($paytypeList[0]['fee1']), $printdoc);
                            $printdoc = str_replace('{销售支付宝}', $this->_2money($paytypeList[1]['fee1']), $printdoc);
                            $printdoc = str_replace('{销售现金}', $this->_2money($paytypeList[2]['fee1']), $printdoc);
                            $printdoc = str_replace('{销售银行卡}', $this->_2money($paytypeList[3]['fee1']), $printdoc);
                            $printdoc = str_replace('{销售会员卡}', $this->_2money($paytypeList[4]['fee1']), $printdoc);
                            $printdoc = str_replace('{销售自定义1}', $shop['custom_pay1'], $printdoc);
                            $printdoc = str_replace('{销售自定义2}', $shop['custom_pay2'], $printdoc);
                            $printdoc = str_replace('{销售自定义3}', $shop['custom_pay3'], $printdoc);
                            $printdoc = str_replace('{销售自定义4}', $shop['custom_pay4'], $printdoc);
                            $printdoc = str_replace('{销售自定义1金额}', $this->_2money($paytypeList[5]['fee1']), $printdoc);
                            $printdoc = str_replace('{销售自定义2金额}', $this->_2money($paytypeList[6]['fee1']), $printdoc);
                            $printdoc = str_replace('{销售自定义3金额}', $this->_2money($paytypeList[7]['fee1']), $printdoc);
                            $printdoc = str_replace('{销售自定义4金额}', $this->_2money($paytypeList[8]['fee1']), $printdoc);
                            $printdoc = str_replace('{充值总金额}', $this->_2money($chargeitem['fee1']), $printdoc);
                            $printdoc = str_replace('{充值微信}', $this->_2money($chargelist[0]), $printdoc);
                            $printdoc = str_replace('{充值支付宝}', $this->_2money($chargelist[1]), $printdoc);
                            $printdoc = str_replace('{充值现金}', $this->_2money($chargelist[2]), $printdoc);
                            $printdoc = str_replace('{充值银行卡}', $this->_2money($chargelist[3]), $printdoc);
                            $printdoc = str_replace('{总退款}', $this->_2money($refundlist['all']), $printdoc);
                            $printdoc = str_replace('{退款微信}', $this->_2money($refundlist[0]), $printdoc);
                            $printdoc = str_replace('{退款支付宝}', $this->_2money($refundlist[1]), $printdoc);
                            $printdoc = str_replace('{退款现金}', $this->_2money($refundlist[2]), $printdoc);
                            $printdoc = str_replace('{退款银行卡}', $this->_2money($refundlist[3]), $printdoc);
                            $printdoc = str_replace('{退款会员卡}', $this->_2money($refundlist[4]), $printdoc);
                            $printdoc = str_replace('{总现金}', $this->_2money($paytypeList[2]['fee1'] + $chargelist[2] - $refundlist[2]), $printdoc);
                            exit(json_encode(array('success' => true, 'content' => $printdoc, 'printtype' => $ptype, 'num' => intval($print['num']) ? $print['num'] : 1)));
                            break;
                        case 10:
                            $print = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_print') . ' WHERE weid = \'' . $_W['uniacid'] . '\' and pcate=\'2\' and groupid=:a order by isdefault desc,id desc limit 1', array(':a' => $shopid));
                            $printdoc = $print['wpcontent'];
                            $trade = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_order') . ' WHERE weid = \'' . $_W['uniacid'] . '\' and id=:a ', array(':a' => $orderid));
                            $username = pdo_fetchcolumn('SELECT realname FROM ' . tablename('j_hmoney_user') . ' WHERE id=:a ', array(':a' => $trade['userid']));
                            $table = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_table') . ' WHERE weid = \'' . $_W['uniacid'] . '\' and id=:a ', array(':a' => $trade['tableid']));
                            $tablepcate = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_tablecategory') . ' WHERE id=:a ', array(':a' => $table['pcate']));
                            $printdoc = str_replace('{收银员}', $username, $printdoc);
                            $printdoc = str_replace('{订单号}', $trade['out_trade_no'], $printdoc);
                            $printdoc = str_replace('{流水号}', $trade['serialnum'], $printdoc);
                            $printdoc = str_replace('{总金额}', $this->_2money($trade['order_fee']), $printdoc);
                            $printdoc = str_replace('{应付}', $this->_2money($trade['total_fee']), $printdoc);
                            $printdoc = str_replace('{优惠}', $this->_2money($trade['discount_fee']), $printdoc);
                            $printdoc = str_replace('{实付}', $this->_2money($trade['paid_fee']), $printdoc);
                            $printdoc = str_replace('{茶位费}', $this->_2money($trade['teafee']), $printdoc);
                            $printdoc = str_replace('{人数}', $trade['person'], $printdoc);
                            $printdoc = str_replace('{房台}', $tablepcate['title'] . '-' . $table['title'], $printdoc);
                            $ispay = '未支付';
                            if ($trade['ispay'] == 0) {
                                $ispay = '未支付';
                            } else {
                                if ($trade['ispay'] == 1) {
                                    $ispay = '已付款';
                                }
                            }
                            $printdoc = str_replace('{支付}', $ispay, $printdoc);
                            $printdoc = str_replace('{状态}', _orderGoodsStatus($trade['status']), $printdoc);
                            if ($trade['paytype2'] > -1) {
                                $str = _getPaytpye($trade['paytype']) . '￥' . $this->_2money($trade['paid_fee1']) . "\\n" . _getPaytpye($trade['paytype2']) . '￥' . $this->_2money($trade['paid_fee2']);
                                $printdoc = str_replace('{付款方式}', $str, $printdoc);
                            } else {
                                $printdoc = str_replace('{付款方式}', _getPaytpye($trade['paytype']), $printdoc);
                            }
                            $printdoc = str_replace('{开台时间}', date('m/d H:i', $trade['createtime']), $printdoc);
                            $printdoc = str_replace('{日期}', $trade['createdate'], $printdoc);
                            $printdoc = str_replace('{时间}', date('H:i'), $printdoc);
                            $printdoc = str_replace('{二维码}', $trade['qrcode'] ? '<QR>' . $trade['qrcode'] . '</QR>' : '', $printdoc);
                            exit(json_encode(array('success' => true, 'content' => $printdoc, 'printtype' => $ptype, 'printerip' => $tablepcate['printerip'], 'num' => intval($print['num']) ? $print['num'] : 1)));
                            break;
                        case 11:
                            if (!$printdoc) {
                                $printdoc = '商品销售汇总<BR>店铺：{店铺}<BR>时间：{时间}<BR>{商品}<BR>---------------<BR>{汇总}<BR>';
                            }
                            $printdoc = str_replace('{店铺}', $shop['companyname'], $printdoc);
                            $printdoc = str_replace('{时间}', date('Y-m-d H:i'), $printdoc);
                            $condition = ' and a.groupid =\'' . $shopid . '\' and a.createtime>=\'' . strtotime(date('Y-m-d 00:00:00')) . '\' and a.createtime<=\'' . strtotime(date('Y-m-d 23:59:59')) . '\'';
                            $goodlist = pdo_fetchall('SELECT max(a.title) as title2, max(a.goodsn) as sn,sum(a.num) as num1,sum(a.total_fee) as fee1,b.marketprice,AVG(a.price) as price2 FROM ' . tablename('j_hmoney_ordergoods') . ' a left join ' . tablename('j_hmoney_goods') . ' b on a.goodid=b.id WHERE a.weid=\'' . $_W['uniacid'] . '\' ' . $condition . '  and a.ispay=1 group by a.goodid order by sum(a.num) desc');
                            $goodstr = '';
                            $Num = 0;
                            $fee = 0;
                            foreach ($goodlist as $row) {
                                $Num = $Num + $row['num1'];
                                $fee = $fee + $row['fee1'];
                                $goodstr .= formatPrintStr($row['title2'], 14) . ' ' . formatPrintStr($row['num1'], 3, 1) . ' ' . formatPrintStr($this->_2money($row['fee1']), 6, 1) . '<BR>';
                            }
                            $printdoc = str_replace('{商品}', $goodstr, $printdoc);
                            $allin = '汇总：         ' . $Num . '  ' . $this->_2money($fee);
                            $printdoc = str_replace('{汇总}', $allin, $printdoc);
                            exit(json_encode(array('success' => true, 'content' => $printdoc, 'printtype' => $ptype, 'num' => intval($print['num']) ? $print['num'] : 1)));
                            break;
                        case 12:
                            $trade = pdo_fetch('SELECT * FROM ' . tablename('j_hmoney_giftrecord') . ' WHERE weid = \'' . $_W['uniacid'] . '\' and out_trade_no=:a ', array(':a' => $orderid));
                            if (!$trade['gtype']) {
                                exit(json_encode(array('success' => false, 'msg' => '无需打印')));
                            }
                            if (!$trade['qrcode']) {
                                exit(json_encode(array('success' => false, 'msg' => '无需打印')));
                            }
                            $printdoc = '<QR>' . $trade['qrcode'] . '</QR>';
                            exit(json_encode(array('success' => true, 'content' => $printdoc, 'printtype' => $ptype, 'num' => 1)));
                            break;
                    }
                    exit(json_encode(array('success' => true, 'list' => 1234)));
                }
            }
        }
    }
}